<template>
  <!-- 添加或修改销售订单行项目信息对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-tabs v-model="activeName" class="detail-tab" type="card">
              <el-tab-pane label="基本信息" name="first">
                  <el-row :gutter="20">
                      <el-col :span="12">
                          <el-form-item label="采购方总部编码" prop="purchaserHqCode">
                              <el-input v-model="form.purchaserHqCode" placeholder="请输入采购方总部编码"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="销售订单号" prop="soNo">
                              <el-input v-model="form.soNo" placeholder="请输入销售订单号"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="供应商编码" prop="supplierCode">
                              <el-input v-model="form.supplierCode" placeholder="请输入供应商编码"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="采购方公司编码" prop="buyerCode">
                              <el-input v-model="form.buyerCode" placeholder="请输入采购方公司编码"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="采购方公司名称" prop="buyerName">
                              <el-input v-model="form.buyerName" placeholder="请输入采购方公司名称"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="采购方公司省份" prop="buyerProvince">
                              <el-input v-model="form.buyerProvince" placeholder="请输入采购方公司省份"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="品类编码" prop="categoryCode">
                              <el-input v-model="form.categoryCode" placeholder="请输入品类编码"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="24">
                        <el-form-item label="备注" prop="remark">
                          <el-input v-model="form.remark" placeholder="请输入备注"/>
                        </el-form-item>
                      </el-col>
                      <!--<el-col :span="12">
                          <el-form-item label="种类编码" prop="subclassCode">
                              <el-input v-model="form.subclassCode" placeholder="请输入种类编码"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="数据拥有方" prop="ownerId">
                              <el-input v-model="form.ownerId" placeholder="请输入数据拥有方"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="数据可见方" prop="openId">
                              <el-input v-model="form.openId" placeholder="请输入数据可见方"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="数据来源" prop="dataSource">
                              <el-input v-model="form.dataSource" placeholder="请输入数据来源"/>
                          </el-form-item>
                      </el-col>
                      <el-col :span="12">
                          <el-form-item label="来源数据创建时间" prop="dataSourceCreateTime">
                              <el-input v-model="form.dataSourceCreateTime" placeholder="请输入来源数据创建时间"/>
                          </el-form-item>
                      </el-col>-->
                  </el-row>
              </el-tab-pane>
          </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
      </div>
  </el-dialog>
</template>

<script>
  import { addAction, getById, updateAction } from '@/api/manage';
  import moment from 'moment';

  export default {
      name: "FactorySaleOrderForm",
      data() {
          return {
              // 遮罩层
              loading: true,
              activeName: "first",
              // 弹出层标题
              title: "",
              // 是否显示弹出层
              open: false,
              // 表单参数
              form: {},
              // 表单校验
              rules: {
              },
              url: {
                  getById:'/factorySaleOrder/factorySaleOrder/',
                  add:'/factorySaleOrder/factorySaleOrder/add',
                  edit:'/factorySaleOrder/factorySaleOrder/edit',
              },
          };
      },
      created() {

      },
      methods: {
          // 取消按钮
          cancel() {
              this.open = false;
              this.reset();
          },
          // 表单重置
          reset() {
              this.form = {
          id: null,
          status: "0",
          remark: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          delFlag: null,
          purchaserHqCode: null,
          soNo: null,
          supplierCode: null,
          buyerCode: null,
          buyerName: null,
          buyerProvince: null,
          categoryCode: "60",
          subclassCode: "60004",
          soStatus: "0",
          ownerId: null,
          openId: null,
          dataSource: null,
          dataSourceCreateTime: null
              };
              this.resetForm("form");
          },
          /** 新增按钮操作 */
          handleAdd() {
              this.reset();
              this.open = true;
              this.title = "添加采购订单";
          },
          /** 修改按钮操作 */
          handleUpdate(row) {
              this.reset();
              const id = row.id || this.ids;
              getById(this.url.getById, id).then(response => {
                  this.form = response.data;
                  this.open = true;
                  this.title = "修改采购订单信息";
              });
          },
          /** 提交按钮 */
          submitForm() {
              this.$refs["form"].validate(valid => {
                  if (valid) {
                      if (this.form.id != null) {
                          updateAction(this.url.edit, this.form).then(response => {
                              this.$modal.msgSuccess("修改成功");
                              this.open = false;
                              this.$emit('ok');
                          });
                      } else {
                          addAction(this.url.add, this.form).then(response => {
                              this.$modal.msgSuccess("新增成功");
                              this.open = false;
                              this.$emit('ok');
                          });
                      }
                  }
              });
          },
      }
  };
</script>
